home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / EmailSender / EmailSender.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  7.3 KB  |  264 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.FlowLayout;
  7. import java.awt.GridLayout;
  8. import java.awt.Label;
  9. import java.awt.Panel;
  10. import java.awt.TextArea;
  11. import java.awt.TextField;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.io.BufferedReader;
  15. import java.io.DataOutputStream;
  16. import java.io.InputStreamReader;
  17. import java.net.Socket;
  18. import java.net.URL;
  19. import java.util.EventObject;
  20.  
  21. public class EmailSender extends Applet implements ActionListener {
  22.    // $FF: renamed from: wi int
  23.    private int field_0;
  24.    // $FF: renamed from: he int
  25.    private int field_1;
  26.    private String fond;
  27.    private String mailServer;
  28.    private TextField tname;
  29.    private TextField tmail;
  30.    private TextField tsubject;
  31.    // $FF: renamed from: ta java.awt.TextArea
  32.    private TextArea field_2;
  33.    // $FF: renamed from: tt java.awt.TextArea
  34.    private TextArea field_3;
  35.    private String text1;
  36.    private String text2;
  37.    private String text3;
  38.    private String text4;
  39.    private String text5;
  40.  
  41.    public String getAppletInfo() {
  42.       return "Name: EmailSender\r\nAuthor: Taiji Software\r\n";
  43.    }
  44.  
  45.    public void register() {
  46.       try {
  47.          URL u = new URL("http://www.taijisoftware.com");
  48.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  49.          ((Applet)this).stop();
  50.       } catch (Exception e) {
  51.          System.out.println(e);
  52.          ((Applet)this).stop();
  53.       }
  54.    }
  55.  
  56.    public void init() {
  57.       String codeBase = null;
  58.  
  59.       try {
  60.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  61.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  62.          codeBase = codeBase.toUpperCase();
  63.       } catch (Exception var9) {
  64.       }
  65.  
  66.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  67.          String regCode = ((Applet)this).getParameter("registration_code");
  68.          if (regCode == null) {
  69.             regCode = ((Applet)this).getParameter("reg_domain");
  70.             if (regCode == null) {
  71.                this.register();
  72.             } else {
  73.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  74.                   codeBase = "WWW." + codeBase;
  75.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  76.                   codeBase = codeBase.substring(4);
  77.                }
  78.  
  79.                char[] chars = new char[codeBase.length()];
  80.                codeBase.getChars(0, codeBase.length(), chars, 0);
  81.                String key = new String("haricot");
  82.                char[] chars2 = new char[key.length()];
  83.                key.getChars(0, key.length(), chars2, 0);
  84.  
  85.                for(int i = 0; i < codeBase.length(); ++i) {
  86.                   int j;
  87.                   if (i >= key.length()) {
  88.                      j = i - key.length() * (i / key.length());
  89.                   } else {
  90.                      j = i;
  91.                   }
  92.  
  93.                   chars[i] += chars2[j];
  94.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  95.                }
  96.  
  97.                String res = new String(chars);
  98.                if (!res.equalsIgnoreCase(regCode)) {
  99.                   this.register();
  100.                }
  101.             }
  102.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  103.             this.register();
  104.          }
  105.       }
  106.  
  107.       this.getParameters();
  108.       ((Container)this).setLayout(new GridLayout(3, 1));
  109.       Panel p1 = new Panel();
  110.       Panel p2 = new Panel();
  111.       Panel p3 = new Panel();
  112.       ((Container)this).add(p1);
  113.       ((Container)this).add(p2);
  114.       ((Container)this).add(p3);
  115.       ((Container)p1).setLayout(new GridLayout(4, 2));
  116.       ((Container)p2).setLayout(new FlowLayout());
  117.       ((Container)p1).add(new Label(this.text1));
  118.       this.tname = new TextField();
  119.       ((Container)p1).add(this.tname);
  120.       ((Container)p1).add(new Label(this.text2));
  121.       this.tmail = new TextField();
  122.       ((Container)p1).add(this.tmail);
  123.       ((Container)p1).add(new Label(this.text3));
  124.       this.tsubject = new TextField();
  125.       ((Container)p1).add(this.tsubject);
  126.       this.field_3 = new TextArea(this.text4, 6, 50);
  127.       ((Container)p2).add(this.field_3);
  128.       ((Container)p2).add(new Label("   "));
  129.       Button b = new Button(this.text5);
  130.       b.addActionListener(this);
  131.       ((Component)b).setSize(40, 20);
  132.       ((Container)p2).add(b);
  133.       this.field_2 = new TextArea("", 4, 60);
  134.       this.field_2.setEditable(false);
  135.       ((Container)p3).add(this.field_2);
  136.    }
  137.  
  138.    public void getParameters() {
  139.       this.field_0 = ((Component)this).getSize().width;
  140.       this.field_1 = ((Component)this).getSize().height;
  141.       this.mailServer = ((Applet)this).getParameter("mail_server");
  142.       if (this.mailServer == null) {
  143.          if (((Applet)this).getCodeBase().getProtocol().equals("file")) {
  144.             this.mailServer = "localhost";
  145.          } else {
  146.             this.mailServer = ((Applet)this).getCodeBase().getHost();
  147.          }
  148.       }
  149.  
  150.       this.text1 = ((Applet)this).getParameter("text1");
  151.       if (this.text1 == null) {
  152.          this.text1 = "Mail from :";
  153.       }
  154.  
  155.       this.text2 = ((Applet)this).getParameter("text2");
  156.       if (this.text2 == null) {
  157.          this.text2 = "Mail to :";
  158.       }
  159.  
  160.       this.text3 = ((Applet)this).getParameter("text3");
  161.       if (this.text3 == null) {
  162.          this.text3 = "Subject :";
  163.       }
  164.  
  165.       this.text4 = ((Applet)this).getParameter("text4");
  166.       if (this.text4 == null) {
  167.          this.text4 = "your message...";
  168.       }
  169.  
  170.       this.text5 = ((Applet)this).getParameter("text5");
  171.       if (this.text5 == null) {
  172.          this.text5 = "Send message";
  173.       }
  174.  
  175.       ((Component)this).setBackground(this.getColor("background_color"));
  176.    }
  177.  
  178.    public Color getColor(String param) {
  179.       String s = ((Applet)this).getParameter(param);
  180.       if (s != null) {
  181.          if (s.substring(0, 1).equals("#")) {
  182.             s = s.substring(1);
  183.             int i = Integer.parseInt(s, 16);
  184.             return new Color(i);
  185.          } else {
  186.             return null;
  187.          }
  188.       } else {
  189.          return null;
  190.       }
  191.    }
  192.  
  193.    public void actionPerformed(ActionEvent evt) {
  194.       if (((EventObject)evt).getSource() instanceof Button) {
  195.          String from = this.tname.getText();
  196.          if (from.length() == 0) {
  197.             this.field_2.append("You must fill out the \"" + this.text1 + "\" field.\n");
  198.             return;
  199.          }
  200.  
  201.          String recipient = this.tmail.getText();
  202.          if (recipient.length() == 0) {
  203.             this.field_2.append("You must fill out the \"" + this.text2 + "\" field.\n");
  204.             return;
  205.          }
  206.  
  207.          this.send(from, recipient);
  208.       }
  209.  
  210.    }
  211.  
  212.    public void send(String from, String recipient) {
  213.       try {
  214.          System.out.println("Trying to connect to " + this.mailServer + " on port 25...");
  215.          this.field_2.append("Trying to connect to " + this.mailServer + " on port 25...\n");
  216.          Socket sock = new Socket(this.mailServer, 25);
  217.          System.out.println("Connected !");
  218.          this.field_2.append("Connected !\n");
  219.          DataOutputStream out = new DataOutputStream(sock.getOutputStream());
  220.          System.out.println("out ok");
  221.          BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
  222.          System.out.println("in ok");
  223.          this.isOk(in);
  224.          out.writeBytes("HELO EmailSender.com\r\n");
  225.          this.isOk(in);
  226.          out.writeBytes("MAIL FROM:" + from + "\r\n");
  227.          this.isOk(in);
  228.          out.writeBytes("RCPT TO:<" + recipient + ">\r\n");
  229.          this.isOk(in);
  230.          out.writeBytes("DATA\r\n");
  231.          this.isOk(in);
  232.          out.writeBytes("Subject: " + this.tsubject.getText() + "\n\n" + this.field_3.getText() + "\r\n.\r\nQUIT\r\n");
  233.          if (this.isOk(in)) {
  234.             this.field_2.append("Your email has been sent !\n");
  235.          }
  236.  
  237.          sock.close();
  238.       } catch (Exception e) {
  239.          System.err.println(e);
  240.          this.field_2.append("Error !!: " + ((Throwable)e).toString() + "\n");
  241.       }
  242.    }
  243.  
  244.    public boolean isOk(BufferedReader in) {
  245.       String s = "";
  246.  
  247.       try {
  248.          s = in.readLine();
  249.          System.out.println(s);
  250.       } catch (Exception var3) {
  251.          ((Applet)this).stop();
  252.          return false;
  253.       }
  254.  
  255.       if (!s.startsWith("4") && !s.startsWith("5")) {
  256.          return true;
  257.       } else {
  258.          this.field_2.append("Error: " + s + "\n");
  259.          ((Applet)this).stop();
  260.          return false;
  261.       }
  262.    }
  263. }
  264.